package com.mz.ozy.adapter;

import android.text.Html;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.mz.ozy.R;
import com.mz.ozy.bean.FamilyFeastBean;
import com.mz.ozy.bean.MyOrderBean;
import com.mz.ozy.bean.OnlineListBean;
import com.mz.ozy.bean.ShogBean;
import com.mz.ozy.utils.Utils;
import com.mz.ozy.utils.glideUtils.GlideUtils;

import java.util.List;

/**
 *
 */

public class MyBookAdapter extends BaseQuickAdapter<OnlineListBean.PageBean.PageItemsBean, BaseViewHolder> {

    public MyBookAdapter(List<OnlineListBean.PageBean.PageItemsBean> data) {
        super(R.layout.item_me_book, data);
//        addData(new OnlineListBean.PageBean.PageItemsBean());
//        addData(new OnlineListBean.PageBean.PageItemsBean());
//        addData(new OnlineListBean.PageBean.PageItemsBean());
//        addData(new OnlineListBean.PageBean.PageItemsBean());
    }

    @Override
    protected void convert(BaseViewHolder helper, OnlineListBean.PageBean.PageItemsBean item) {
//        helper.setText(R.id.tv_title, item.getTitle());
//        helper.setText(R.id.tv_time, item.getCreated());
        ImageView iv_image = helper.getView(R.id.iv_image);
        String img_zt = "";
        if (!TextUtils.isEmpty(item.getImg())) {
            final String[] splitImgZt = item.getImg().split(",");
            if (splitImgZt.length > 0) {
                img_zt = splitImgZt[0];
            }
        }
        GlideUtils.loadImg(mContext, iv_image, img_zt, R.mipmap.default_foods_icon);
        helper.setText(R.id.tv_title, item.getName());
        if (!TextUtils.isEmpty(item.getPaper())) {
            String regFormat = "\\s*|\t|\r|\n";
            String regTag = "<[^>]*>";
            String text = item.getPaper().replaceAll(regFormat, "").replaceAll(regTag, "");
            helper.setText(R.id.tv_desc1, text);
        } else {
            helper.setText(R.id.tv_desc1, "");
        }
        helper.setText(R.id.tv_price, "¥" + Utils.decimalUtils(item.getPrice(), 2));
        helper.setText(R.id.tv_shop_name, item.getDpname());
        helper.setText(R.id.tv_box_name, item.getBjname());
        helper.setText(R.id.tv_book_time, "预订就餐时间：" + item.getMealdata() + " " + item.getMealtime());
        helper.setText(R.id.tv_submit_time, "提交时间：" + item.getCreated());
        helper.setText(R.id.tv_book_space, item.getYman() + "人");
        if (item.getState() == 0) {
            helper.setVisible(R.id.tv_pay_book, true);
        } else {
            helper.setGone(R.id.tv_pay_book, false);
        }
        if (item.getState() == 0 || item.getState() == 1) {
            helper.setVisible(R.id.tv_cancel_book, true);
            helper.setVisible(R.id.ll_book_bottom, true);
        } else {
            helper.setGone(R.id.tv_cancel_book, false);
            helper.setGone(R.id.ll_book_bottom, false);
        }
        TextView tvTime = helper.getView(R.id.tv_time);
        switch (item.getState()) {
            case 0:
                helper.setText(R.id.tv_pay_state, "待支付");
                tvTime.setVisibility(View.VISIBLE);
                startCountDown(item, tvTime);
                break;
            case 1:
                helper.setText(R.id.tv_pay_state, "已支付");
                tvTime.setVisibility(View.GONE);
                break;
            case 2:
                helper.setText(R.id.tv_pay_state, "已取消");
                tvTime.setVisibility(View.GONE);
                break;
            case 3:
                helper.setText(R.id.tv_pay_state, "取消待审核");
                tvTime.setVisibility(View.GONE);
                break;
            case 4:
                helper.setText(R.id.tv_pay_state, "待退款");
                tvTime.setVisibility(View.GONE);
                break;
            case 5:
                helper.setText(R.id.tv_pay_state, "已退款");
                tvTime.setVisibility(View.GONE);
                break;
            case 6:
                helper.setText(R.id.tv_pay_state, "已完成");
                tvTime.setVisibility(View.GONE);
                break;
        }
        helper.addOnClickListener(R.id.ll_item_view);
        helper.addOnClickListener(R.id.tv_cancel_book);
        helper.addOnClickListener(R.id.tv_pay_book);
    }

    private void startCountDown(OnlineListBean.PageBean.PageItemsBean item, TextView view) {
        view.setText(mContext.getString(R.string.countdown_msg, Utils.long2DateStr(item.getSpaceTime())));
    }
}
